package com.android.semita.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.android.semita.InvoiceMapper;
import com.android.semita.model.Invoice;
import com.android.semita.model.InvoiceItem;

public class InvoiceController {
	public Invoice GetInvoiceByInvoiceNumber(String InvoiceNo)
	{
		Invoice invoice = new Invoice();
		invoice.setInvoiceNo("SI-131100001");
		
		
		try {
			SimpleDateFormat sdf =  new SimpleDateFormat("yyyy, MM, dd");
	        Date date;
	        
			date = sdf.parse("2013, 12, 11");		
	        
			invoice.setInvoiceDate(date);
			invoice.setCustomerId("1001");
			invoice.setCustomerName("Nathawat Namtong");
			invoice.setCustomerAddress("2 Silom Rd. flr.14, silom Bangkok 10120");
			
			InvoiceItem invoiceItem = new InvoiceItem();
			invoiceItem.setProductID("5010111");
			invoiceItem.setProductName("T-Shirt 2002");
			invoiceItem.setQuantity(2);
			invoiceItem.setItemAmount(250);
			invoice.Items.add(invoiceItem);
			
			
			invoiceItem = new InvoiceItem();
			invoiceItem.setProductID("5010112");
			invoiceItem.setProductName("T-Shirt AB-002");
			invoiceItem.setQuantity(1);
			invoiceItem.setItemAmount(550);
			invoice.Items.add(invoiceItem);
			
			invoiceItem = new InvoiceItem();
			invoiceItem.setProductID("5010113");
			invoiceItem.setProductName("T-Shirt AIIZ-002");
			invoiceItem.setQuantity(2);
			invoiceItem.setItemAmount(650);
			invoice.Items.add(invoiceItem);
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return invoice;
	}

	private ArrayList<Invoice> Invoices = new ArrayList<Invoice>();
	public ArrayList<Invoice> GetInvoicesByMessengerID(int MessengerID,String DeliveryDate)
	{
		
		/*
		String RequestURL = "http://202.21.149.53/SemitaServices/api/invoice?messengerId=1&target_date=2013-02-11";
			
		Invoice invoice;
		String invoiceNo="";
		
		for(Integer i=1; i<= 30; i++)
		{
			invoiceNo = "00000".concat(i.toString());
			invoiceNo = "SI-1311".concat(invoiceNo.substring(invoiceNo.length()-5));
						
			invoice= new Invoice();
			invoice.setInvoiceNo(invoiceNo);
			invoice.setCustomerName("Customer Name" + i);
			invoice.setInvoiceAmount(2400 + (i*100));
			invoices.add(invoice);			
		}*/
		
		
		
		return Invoices;
	}
	
	public Invoice getInvoiceFromJSON(String JSONString)
	{
		Invoice invoice = new InvoiceMapper().getInvoiceFromJSON(JSONString);
		
		return invoice;
	}

	
		
}
